package com.linpq.road.controller;

import com.linpq.common.annotation.Log;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdRoadSection;
import com.linpq.road.service.RdRoadSectionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * @Author GothamFish
 * @Date 2021/08/04/9:38
 * @Description
 */
@Controller
@RequestMapping("/road/road_map")
public class RdMapController extends BaseController {

    @Autowired
    private RdRoadSectionService rdRoadSectionService;

    private String prefix = "road/road_map";

    @RequiresPermissions("road:road_map:view")
    @GetMapping()
    public String road_section() {
        return prefix + "/road_map";
    }

    /**
     * 跳转到经纬度上传和修改界面
     */
    @GetMapping("/upload/{id}")
    public String upload(@PathVariable("id") String id, ModelMap mmap) {
        RdRoadSection roadSection = rdRoadSectionService.get(id);
        mmap.put("roadSection",roadSection);
        return prefix + "/upload_section_map_info";
    }

    /**
     *  经纬度上传或修改内容
     * @param rdRoadSection
     * @return
     */
    @RequiresPermissions("road:road_map:edit")
    @Log(title = "路段经纬度信息", businessType = BusinessType.UPDATE)
    @PostMapping("/upload")
    @ResponseBody
    public AjaxResult uploadSave(RdRoadSection rdRoadSection) {
        return toAjax(rdRoadSectionService.updateRdRoadSection(rdRoadSection));
    }
}
